import requests
import re

# 1.页面源代码

url = "https://www.dygod.net/"
resp = requests.get(url)    #verify=False 去掉安全验证
resp.encoding = "gb2312"
resp.close()

# 2.提取内容，精确的所需模块

obj = re.compile(r'华语电视剧.*?'
                 r'<ul>(?P<context>.*?)</ul>',re.S)
obj2 = re.compile(r"<a href='(?P<href>.*?)'.*?</a>",re.S)         # ----html中 a标签 ：表示超链接 <a href="url">。。。。</a> 括起来的是某个网页链接。
obj3 = re.compile(r'◎片　　名(?P<title>.*?)<br />.*?'
                  r'<li><a href="(?P<download>.*?)">.*?</a></li>',re.S)

result = obj.finditer(resp.text)
for i in result:
    #print(i.group("context"))  #所需模块内容

    # 3.从提取模块中提取部分所需信息
    result2 = obj2.finditer(i.group("context"))
    for ii in result2:
        #print('https://www.dygod.net/{0}'.format(ii.group("href")))    #模块中部分电影的url
        child_url = url + ii.group("href")
        child_resp = requests.get(child_url)
        child_resp.encoding = 'gb2312'

        result3 = obj3.finditer(child_resp.text)
        for iii in result3:
            print('电影名：{0}'.format(iii.group('title')))
            print('下载地址：{0}'.format(iii.group('download')))
